package cn.com.headfree.workflow.controller;

import cn.com.headfree.base.controller.ExBaseController;
import cn.com.headfree.base.controller.ResultData;
import cn.com.headfree.entity.THonorInfo;
import cn.com.headfree.entity.TSdtTutorPrentInfo;
import cn.com.headfree.entity.TWorkExpInfo;
import cn.com.headfree.entity.isc.User;
import cn.com.headfree.util.SysDictionaryUtil;
import cn.com.headfree.vo.complex.TProjAchieveInfoVo;
import cn.com.headfree.vo.workflow.DbCount;
import cn.com.headfree.vo.workflow.ProcessListVo;
import cn.com.headfree.workflow.service.IWorkFlowProcessService;
import com.gta.edu.sdk.common.dto.Page;

import net.sf.json.JSONObject;

import org.apache.http.impl.bootstrap.HttpServer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

/**
 * @program: human-manage-parent
 * @description: 流程进度查询
 * @author: panl
 * @create: 2020-07-03 15:43
 **/
@Controller
@RequestMapping("/workFlowProcess")
public class WorkFlowProcessController extends ExBaseController {
    private static final Logger LOG = LogManager.getLogger(WorkFlowProcessController.class);
    @Autowired
    public IWorkFlowProcessService iWorkFlowProcessService;

    /*
     * @Description: 进度查看
     * @Param: []
     * @return: void
     * @Author: panl
     * @createTime: 2020/7/3 16:18
     */
    @RequestMapping("/queryProcess")
    @ResponseBody
    public ResultData queryProcess(@RequestBody ProcessListVo processListVo ,HttpServletRequest request){
        LOG.info("流程进度查询：参数为："+ JSONObject.fromObject(processListVo).toString());
        
        Page<ProcessListVo> page = new Page<ProcessListVo>(processListVo.getPageNo(), processListVo.getPageSize());
        ResultData resultData = new ResultData();
        User user =this.getLoginUserInfo(request);
        try{
            iWorkFlowProcessService.queryProcess(processListVo,page,user);
            resultData.setData(page);
        }catch (Exception e){
            resultData.setSuccess(false);
            resultData.setErrorMsg("流程进度查询失败！");
            LOG.error("流程进度查询：查询异常：",e);
        }
        return resultData;
        
    }
    @RequestMapping("/queryBusinessTypeLsit")
    @ResponseBody
    public ResultData queryBusinessTypeLsit(HttpServletRequest request){        
        ResultData resultData = new ResultData();
        User user =this.getLoginUserInfo(request);
        try{
            List<DbCount> list = iWorkFlowProcessService.queryBusinessTypeLsit(user);
            resultData.setData(list);
        }catch (Exception e){
            resultData.setSuccess(false);
            resultData.setErrorMsg("流程进度查询业务类型失败！");
            LOG.error("流程进度查询业务类型：查询业务类型异常：",e);
        }
        return resultData;
        
    }
    @RequestMapping("/deleteProcess")
    @ResponseBody
    public ResultData deleteProcess(@RequestBody ProcessListVo processListVo){
        LOG.info("流程进度删除：参数为："+ JSONObject.fromObject(processListVo).toString());
        ResultData resultData = new ResultData();
        try{
            int num = iWorkFlowProcessService.deleteProcess(processListVo);
            if(num<=0){
                resultData.setSuccess(false);
                resultData.setErrorMsg("流程进度删除失败！");
            }
        }catch (Exception e){
            resultData.setSuccess(false);
            resultData.setErrorMsg("流程进度删除失败！");
            LOG.error("流程进度删除：查询异常：",e);
        }
        return resultData;
    }

    @RequestMapping("/updateProcess")
    @ResponseBody
    public void updateProcess(String value,String dictName) {
        SysDictionaryUtil.getValueByValueAndName(value,dictName);
    }

}
